/**
 * Friction joint. This is used for top-down friction.
 * It provides 2D translational friction and angular friction.
**/
public class b2FrictionJoint extends b2Joint {

	b2Vec2 m_localAnchorA;
	b2Vec2 m_localAnchorB;

	float m_maxForce;
	float m_maxTorque;

	public b2FrictionJoint(int addr) {
		super(addr);

		m_localAnchorA = new b2Vec2(jniLocalAnchorA(address));
		m_localAnchorB = new b2Vec2(jniLocalAnchorB(address));
	}

	@Override
	public void release() {
		if ( address != 0 ) {
			m_localAnchorA.address = 0;
			m_localAnchorB.address = 0;
			super.release();
		}
	}

	public b2Vec2 GetAnchorA() {
		return m_bodyA.GetWorldPoint(m_localAnchorA);
	}

	public b2Vec2 GetAnchorB() {
		return m_bodyB.GetWorldPoint(m_localAnchorB);
	}

	/**remember to call release() on the returned instance*/
	public b2Vec2 GetReactionForce(float inv_dt) {
		return new b2Vec2(jniGetReactionForce(address, inv_dt));
	}

	public float GetReactionTorque(float inv_dt) {
		return jniGetReactionTorque(address, inv_dt);
	}

	/**The local anchor point relative to bodyA's origin.(don't call release())*/
	public b2Vec2 GetLocalAnchorA() {
		return m_localAnchorA;
	}

	/**The local anchor point relative to bodyB's origin.(don't call release())*/
	public b2Vec2 GetLocalAnchorB() {
		return m_localAnchorB;
	}

	/// Set the maximum friction force in N.
	public void SetMaxForce(float force) {
		jniSetMaxForce(address, force);
		m_maxForce = force;
	}

	/// Get the maximum friction force in N.
	public float GetMaxForce() {
		return m_maxForce;
	}

	/// Set the maximum friction torque in N*m.
	public void SetMaxTorque(float torque) {
		jniSetMaxTorque(address, torque);
		m_maxTorque = torque;
	}

	/**Get the maximum friction torque in N*m.*/
	public float GetMaxTorque() {
		return m_maxTorque;
	}

	private static native int jniLocalAnchorA(int me);
	private static native int jniLocalAnchorB(int me);
	private static native int jniGetReactionForce(int me, float inv_dt);
	private static native float jniGetReactionTorque(int me, float inv_dt);
	private static native void jniSetMaxForce(int me, float force);
	private static native void jniSetMaxTorque(int me, float torque);

}
